﻿Imports System.Net.Mail
Imports System.Data
Imports Alerts

Partial Class Pages_ZapHeslo
    Inherits BasePage
    Public alert As Alerts = New Alerts
    Protected Sub BTB_odeslat_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTB_odeslat.Click
        Dim dsZakaznik As DataView = CType(DS_Zakaznik.Select(DataSourceSelectArguments.Empty), DataView)
        If dsZakaznik.Table.Rows.Count <> 0 Then

            posliHeslo(dsZakaznik.Table.Rows(0)("Mail"), dsZakaznik.Table.Rows(0)("Heslo"))
        Else
            alert.Show(String.Format(GetLocalResourceObject("alert_nenalezeno"), TXB_uzivatel.Text), GetLocalResourceObject("title"))
        End If
    End Sub

    Private Sub posliHeslo(ByVal mailAdr As String, ByVal heslo As String)
        'Odeslani objednavky
        Dim sb As StringBuilder = New StringBuilder
        Dim Msg As New MailMessage()
        Dim Senderx As New SmtpClient()
        Dim adresat As MailAddress



        sb.Append(String.Format(GetLocalResourceObject("msg_message"), RTrim(heslo)))
        sb.AppendLine()


        'Poslat mail
        Msg.From = New System.Net.Mail.MailAddress("obchod@horejsi.cz", "e-Obchod Hořejší")
        Msg.Subject = GetLocalResourceObject("msg_subject").ToString
        Msg.Body = sb.ToString

        adresat = New MailAddress(mailAdr)
        Msg.To.Add(adresat)
        Msg.IsBodyHtml = True
        Try
            Senderx.Send(Msg)
            alert.Show(String.Format(GetLocalResourceObject("alert_nalezeno"), TXB_uzivatel.Text), GetLocalResourceObject("title"))
        Catch ex As Exception
            alert.Show(String.Format(GetLocalResourceObject("alert_neodeslano"), TXB_uzivatel.Text), GetLocalResourceObject("title"))
        End Try
    End Sub

End Class
